<?php

namespace app\common\model;

use think\Model;


class Duty extends Model
{

    

    

    // 表名
    protected $name = 'duty';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'types_text',
        'duty_time_text'
    ];
    

    
    public function getTypesList()
    {
        return ['1' => __('Types 1'), '2' => __('Types 2'), '3' => __('Types 3'), '4' => __('Types 4')];
    }


    public function getTypesTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['types']) ? $data['types'] : '');
        $list = $this->getTypesList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDutyTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['duty_time']) ? $data['duty_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setDutyTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
    public function people1(){
        return $this->belongsTo(People::class,'people1_id');
    }
    public function people2(){
        return $this->belongsTo(People::class,'people2_id');
    }
    public function people3(){
        return $this->belongsTo(People::class,'people3_id');
    }
    public function people4(){
        return $this->belongsTo(People::class,'people4_id');
    }

}
